package org.jeecg.modules.business.homepage.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.business.homepage.vo.PageTotalVo;
import org.jeecg.modules.business.homepage.vo.TypeNumVO;
import org.jeecg.modules.business.rlzy.entity.BuGsfwptRlzy;
import org.jeecg.modules.business.rlzy.service.IBuGsfwptRlzyService;
import org.jeecg.modules.system.service.ISysLogService;
import org.jeecg.modules.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Program: jzzx-sjfwpt-nw
 * @Description:
 * @Author: liuye
 * @Create: 2022-11-21 19:14
 * @Version 1.0
 */
@Api(tags="首页接口")
@RestController
@RequestMapping("/business/homepage")
@Slf4j
public class HomePageController extends JeecgController<BuGsfwptRlzy, IBuGsfwptRlzyService> {
    @Autowired
    private ISysLogService sysLogService;
    @Autowired
    private ISysUserService iSysUserService;
    @Autowired
    private IBuGsfwptRlzyService buGsfwptRlzyService;
    /**
     * 查询统计系统数据总体情况
     * @return
     */
    @AutoLog(value = "首页接口-查询统计系统数据总体情况")
    @ApiOperation(value="首页接口-查询统计系统数据总体情况", notes="首页接口-查询统计系统数据总体情况")
    @PutMapping(value = "/totalTypeNum")
    public Result<?> totalTypeNum() {
        PageTotalVo pv = buGsfwptRlzyService.totalTypeNum();
        return Result.OK(pv);
    }
    /**
     * 首页数据总量
     * @return
     */
    @AutoLog(value = "首页接口-根据企业统计数据")
    @ApiOperation(value="首页接口-根据企业统计数据", notes="首页接口-根据企业统计数据")
    @PutMapping(value = "/totalDataByQy")
    public Result<?> totalDataByQy(String wslx) {
        if(StringUtils.isNotBlank(wslx)){
            List<PageTotalVo> pvList = buGsfwptRlzyService.totalDataByQy(wslx);
            return Result.OK(pvList);
        }else {
            return Result.error("参数为空!") ;
        }

    }
    /**
     * 根据主体统计数据
     * @return
     */
    @AutoLog(value = "首页接口-根据主体统计数据")
    @ApiOperation(value="首页接口-根据主体统计数据", notes="首页接口-根据主体统计数据")
    @PutMapping(value = "/totalDataByZt")
    public Result<?> totalDataByZt(String wslx) {
        Map<String , Object> resultMap = new HashMap<>() ;
        if(StringUtils.isNotBlank(wslx)){
            List<PageTotalVo> pvList = buGsfwptRlzyService.totalDataByZt(wslx);
            List<String> nameList = new ArrayList<>() ;
            List<Double> bsrList = new ArrayList<>() ;
            List<Double> jsjeList = new ArrayList<>() ;
            List<Double> ydzseList = new ArrayList<>() ;
            List<Double> sjseList = new ArrayList<>() ;
            for(PageTotalVo pv : pvList){
                nameList.add(pv.getDzzt());
                bsrList.add(pv.getBsrNum());
                jsjeList.add(pv.getJsjeNum());
                ydzseList.add(pv.getYdzseNum());
                sjseList.add(pv.getSjseNum());
            }
            resultMap.put("name" , nameList);
            resultMap.put("bsr" , bsrList);
            resultMap.put("jsje" , jsjeList);
            resultMap.put("ydzse" , ydzseList);
            resultMap.put("sjse" , sjseList);
            return Result.OK(resultMap);
        }else {
            return Result.error("参数为空!") ;
        }

    }

    /**
     * 平台访问量，登录访问量
     * @return
     */
    @AutoLog(value = "首页接口-平台用户-平台访问量")
    @ApiOperation(value="首页接口-平台用户-平台访问量", notes="首页接口-平台用户-平台访问量")
    @PutMapping(value = "/userVisits")
    public Result<?> userVisits() {
        Long visitCount = sysLogService.findTotalVisitCount();
        return Result.OK(visitCount);
    }
    /**
     * 日均平台访问量，登录访问量
     * @return
     */
    @AutoLog(value = "首页接口-平台用户-日均平台访问量")
    @ApiOperation(value="首页接口-平台用户-日均平台访问量", notes="首页接口-平台用户-日均平台访问量")
    @PutMapping(value = "/userAveVisits")
    public Result<?> userAveVisits() {
        Long visitCount = sysLogService.userAveVisits();
        return Result.OK(visitCount);
    }
    /**
     * 注册用户
     * @return
     */
    @AutoLog(value = "首页接口-平台用户-注册用户")
    @ApiOperation(value="首页接口-平台用户-注册用户", notes="首页接口-平台用户-注册用户")
    @PutMapping(value = "/registerUser")
    public Result<?> registerUser() {
        int userCount = iSysUserService.registerUser();
        return Result.OK(userCount);
    }

    /**
     * 日均在线用户
     * @return
     */
    @AutoLog(value = "首页接口-平台用户-日均在线用户")
    @ApiOperation(value="首页接口-平台用户-日均在线用户", notes="首页接口-平台用户-日均在线用户")
    @PutMapping(value = "/userAveOnLine")
    public Result<?> userAveOnLine() {
        Long onLineCount = sysLogService.userAveOnLine();
        return Result.OK(onLineCount);
    }



}
